import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [ //定义一级路由
  // 路由地址中带有 ：xxx 的路由地址 都属于动态路由
  // path: '/index/:name', // :name 是个占位符，实际在跳路由的时候，会动态拼接参数 例如：'/detail'+100
  {
    path: '/index',
    name: 'index',
    component: () => import('../views/Index.vue'),
    children: [ //嵌套路由(二级路由)
      {
        path: '/index/home',
        name: 'home',
        component: () => import('../views/Index/Home.vue')
      },
      {
        path: '/index/tuan',
        name: 'tuan',
        component: () => import('../views/Index/Tuan.vue')
      },
      {
        path: '/index/order',
        name: 'order',
        component: () => import('../views/Index/Order.vue')
      },
      {
        path: '/index/mine',
        name: 'mine',
        component: () => import('../views/Index/Mine.vue')
      },
      // 二级路由的重定向
      {
        path: '/index',
        redirect: '/index/home'
      },
      // 404路由
      {
        path: '*',
        component: () => import('../views/NotFound.vue')
      }
    ]
  },
  // 一级路由重定向
  {
    path: '/',
    redirect: '/index'
  },
  // 404路由
  {
    path: '*',
    component: () => import('../views/NotFound.vue')
  }
]

const router = new VueRouter({
  mode: 'history', //设置路由模式，history，hash
  base: process.env.BASE_URL,
  routes
})

export default router
